package com.hjw.exer;

/**
 * 学生选课系统，学生类
 * 学生因该具备的功能：
 *      添加课程、删除课程、查看课程信息。（学生最多同时拥有三个选修课）
 * @author hjwStrart
 * @create 2022-01-07 19:19
 */
public class Student {
    private String name;  //姓名
    private String no;  //学号
    private String gender;  //性别
    private Integer grader;//成绩
    private Course[] courses;  //课程集合

    public Student() {
    }

    public Student(String name, String no, String gender, Integer grader, Course[] courses) {
        this.name = name;
        this.no = no;
        this.gender = gender;
        this.grader = grader;
        this.courses = courses;
    }

    public Integer getGrader() {
        return grader;
    }

    /**
     * 添加了校验功能，成绩若小于0或大于100则设置成绩为默认值
     * @param grader
     */
    public void setGrader(Integer grader) {
        if( grader < 0 || grader > 100){
            this.grader = 60;
        }else{
            this.grader = grader;
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getNo() {
        return no;
    }

    public void setNo(String no) {
        this.no = no;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public Course[] getCourses() {
        return courses;
    }

    public void setCourses(Course[] courses) {
        this.courses = courses;
    }


    /**
     * 显示选修的所有课程的基本信息
     */
    public void getAllCoursesInfo(){
        for (Course cours : courses) {
            System.out.println(cours);
        }
    }

    /**
     * 显示学生基本信息
     * @return
     */
    @Override
    public String toString() {
        return  "姓名=" + name +
                ", 学号=" + no +
                ", 性别=" + gender +
                ", 成绩=" + grader;
    }

    public static void printStuInfoByGrader(Student[] stus){

        Student temp = null;
        for (int i = 0; i < stus.length - 1; i++) {
            for (int j = 0; j < stus.length - 1 - i ; j++) {
                if(stus[j].getGrader() < stus[j +1].getGrader()){
                    temp = stus[j + 1];
                    stus[j+1] = stus[j];
                    stus[j] = temp;
                }
            }
        }
    }


}
